package com.cloud.tsp.controller;

import com.cloud.api.domain.stats.QueryAreal;
import com.cloud.api.domain.stats.VehicleRunningData;
import com.cloud.log.annotation.Log;
import com.cloud.log.enums.BusinessType;
import com.cloud.log.enums.OperatorType;
import com.cloud.mybatis.domain.TableDataInfo;
import com.cloud.tsp.config.MysqlConfig;
import com.cloud.tsp.service.IVehicleRunningDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import java.io.IOException;

/**
 * <p>
 * OLAP 前端控制器
 * </p>
 *
 * @author haohaibo
 * @since 2023-12-29
 */
@RestController
@RequestMapping("/vehicle-running-data")
public class VehicleRunningDataController {

    @Resource
    private IVehicleRunningDataService vehicleRunningDataService;
    @Autowired
    private MysqlConfig mysqlConfig;

    @Tag(name = "v1.0")
    @Operation(summary = "车辆运行数据（车辆统计）")
    @PostMapping("/getVehicleList")
    @Log(title = "统计分析-车辆运行数据（车辆统计）", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public TableDataInfo<VehicleRunningData> selectVehicleList(@RequestBody @Valid QueryAreal para){
        para.setDataSource(mysqlConfig.getDataSource());
        return vehicleRunningDataService.selectVehicleList(para);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "车辆运行数据（车型统计）")
    @PostMapping("/getModelList")
    @Log(title = "统计分析-车辆运行数据（车型统计）", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public TableDataInfo<VehicleRunningData> selectModelList(@RequestBody @Valid QueryAreal para){
        para.setDataSource(mysqlConfig.getDataSource());
        return vehicleRunningDataService.selectModelList(para);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "车辆运行数据导出")
    @PostMapping("/exportVehicleList")
    @Log(title = "统计分析-车辆运行数据导出", businessType = BusinessType.EXPORT, operatorType = OperatorType.MANAGE)
    public void exportVehicleList(QueryAreal para, HttpServletResponse response) throws IOException {
        para.setDataSource(mysqlConfig.getDataSource());
        vehicleRunningDataService.exportVehicleList(para,response);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "车型运行数据导出")
    @PostMapping("/exportModelList")
    @Log(title = "统计分析-车型运行数据导出", businessType = BusinessType.EXPORT, operatorType = OperatorType.MANAGE)
    public void exportModelList(QueryAreal para, HttpServletResponse response) throws IOException {
        para.setDataSource(mysqlConfig.getDataSource());
        vehicleRunningDataService.exportModelList(para,response);
    }
}